package cn.gotom.pinggu.service;

import java.util.List;

import org.apache.log4j.Logger;

import cn.gotom.core.dao.JdbcUtils;
import cn.gotom.core.pojos.StatusEnum;
import cn.gotom.core.pojos.User;
import cn.gotom.core.service.UserService;
import cn.gotom.pinggu.vo.YHXXB;

import com.google.inject.Inject;

public class SyncUserServiceImpl implements SyncUserService
{
	private final Logger log = Logger.getLogger(getClass());

	@Inject
	private UserService userService;

	@Inject
	private DataService dataService;

	@Override
	public void syncUser()
	{
		// List<User> userList = userService.findAll();
		List<YHXXB> yhxxbList = dataService.findAllYHXXB();
		JdbcUtils.closeCurrent();
		log.info("同步用户总数据=" + yhxxbList.size());
		for (YHXXB e : yhxxbList)
		{
			User user = userService.get("username", e.getUser_id());
			if (user == null)
			{
				user = new User();
			}
			user.setUsername(e.getUser_id());
			user.setPassword(e.getUser_ps());
			user.setStatus(StatusEnum.valueOf(e.getStatus()));
			user.setName(e.getMS());
			user.setFj(e.getFJNAME());
			user.setOrganization(e.getFJ());
			if (e.getCreate_date() != null)
			{
				user.setDateCreate(e.getCreate_date());
			}
			userService.save(user);
		}
	}

}
